<?php

/**
 * Created by PhpStorm.
 * User: luzhaoyang
 * Date: 2017/6/28
 * Time: 14:50
 */
class Kdt_customer_model extends Base_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function getCustomers($start,$end)
    {
        $ret = $this->db->select('c.receiver,c.mobile,c.province,c.city,c.district,COUNT(c.id) as trades,SUM(t.payment) as payment,')
            ->from('kdt_consigns as c')
            ->join('kdt_trades as t','c.tid=t.tid','left')
            ->where(array('c.created>'=>$start,'c.created<'=>$end))
            ->group_by('c.mobile,c.receiver,c.province,c.city,c.district')
            ->order_by('payment','DESC')
            ->get()->result_array();
        foreach ($ret as &$row){
            $row['payment']/=100;
        }
        array_unshift($ret,array('姓名','电话','省份','城市','区域','购买次数','消费金额'));
        return $ret;
    }

}